<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./js/vue2.js"></script>
</head>

<body>
    <div id="app">
        <father></father>
    </div>
    <template id="father">
        <div class="father">
            <h1>我是叫做{{fname}}的父组件 </h1>
            <p>儿子今天告诉说他有女朋友了，叫做{{erxifu}}</p>
            <son @getname="ok" :getgoodmessage="goodmessage" ></son>
        </div>
    </template>
    <template id="son">
        <div class="son">
            <h1>我是叫做{{sname}}的子组件 </h1>
            <p>今天我父亲告诉我个好消息说{{getgoodmessage}}</p>
            <input type="button" value="告诉父亲" @click="callname">
        </div>
    </template>
</body>
<script>
    var car = new Vue()
    Vue.component('father', {
        template: '#father',
        data() {
            return {
                fname: "jack",
                goodmessage: "富二代",
                erxifu:'??'
            }
        },
        methods:{
            ok(data){
               this.erxifu=data;
            }
        },
        components: {
            'son': {
                template: "#son",
                props: ['getgoodmessage'],
                data() {
                    return {
                        sname: "tom",
                        gfname: "lucy",
                    }
                },
                methods: {
                    callname(){
                        this.$emit('getname',this.gfname)
                    }
                }
            }
        }
    })
    var vm = new Vue({
        el: "#app",
        data: {

        }
    })
</script>

</html>